diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx')
| -rw-r--r-- | src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx b/src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx new file mode 100644 index 0000000..4ae819e --- /dev/null +++ b/src/app/(main)/websites/[websiteId]/settings/WebsiteEditForm.tsx @@ -0,0 +1,55 @@ +import { Form, FormButtons, FormField, FormSubmitButton, TextField } from '@umami/react-zen'; +import { useMessages, useUpdateQuery, useWebsite } from '@/components/hooks'; +import { DOMAIN_REGEX } from '@/lib/constants'; + +export function WebsiteEditForm({ websiteId, onSave }: { websiteId: string; onSave?: () => void }) { + const website = useWebsite(); + const { formatMessage, labels, messages, getErrorMessage } = useMessages(); + const { mutateAsync, error, touch, toast } = useUpdateQuery(`/websites/${websiteId}`); + + const handleSubmit = async (data: any) => { + await mutateAsync(data, { + onSuccess: async () => { + toast(formatMessage(messages.saved)); + touch('websites'); + touch(`website:${website.id}`); + onSave?.(); + }, + }); + }; + + return ( + <Form onSubmit={handleSubmit} error={getErrorMessage(error)} values={website}> + <FormField name="id" label={formatMessage(labels.websiteId)}> + <TextField data-test="text-field-websiteId" value={website?.id} isReadOnly allowCopy /> + </FormField> + <FormField + label={formatMessage(labels.name)} + data-test="input-name" + name="name" + rules={{ required: formatMessage(labels.required) }} + > + <TextField /> + </FormField> + <FormField + label={formatMessage(labels.domain)} + data-test="input-domain" + name="domain" + rules={{ + required: formatMessage(labels.required), + pattern: { + value: DOMAIN_REGEX, + message: formatMessage(messages.invalidDomain), + }, + }} + > + <TextField /> + </FormField> + <FormButtons> + <FormSubmitButton data-test="button-submit" variant="primary"> + {formatMessage(labels.save)} + </FormSubmitButton> + </FormButtons> + </Form> + ); +} |